<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/5/30 0030
  Time: 17:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%String path = request.getContextPath();%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!-- Job List Start -->
<c:forEach items="${pageInfo.list}" var="companyPosition">
    <!-- Job List Start -->
    <a href="<%=path%>/web/job/single?CPId=${companyPosition.id}" class="job-list">
        <div class="company-logo col-auto">
            <img src="<%=path%>/assets/images/companies/company-1.png" alt="Company Logo">
        </div>
        <div class="salary-type col-auto order-sm-3">
            <span class="salary-range">$${companyPosition.salaryMin} - $${companyPosition.salaryMax}</span>
            <c:if test="${companyPosition.positionAttr.id eq 1}">
                <span class="badge badge-warning">${companyPosition.positionAttr.attr}</span>
            </c:if>
            <c:if test="${companyPosition.positionAttr.id eq 2}">
                <span class="badge badge-success">${companyPosition.positionAttr.attr}</span>
            </c:if>
            <c:if test="${companyPosition.positionAttr.id eq 3}">
                <span class="badge badge-info">${companyPosition.positionAttr.attr}</span>
            </c:if>
            <c:if test="${companyPosition.positionAttr.id eq 4}">
                <span class="badge badge-danger">${companyPosition.positionAttr.attr}</span>
            </c:if>
        </div>
        <div class="content col">
            <h6 class="title">${companyPosition.name}</h6>
            <ul class="meta">
                <li><strong class="text-primary">${companyPosition.company.companyName}</strong></li>
                <li><i class="fa fa-map-marker"></i> 2020 ${companyPosition.city.cityName}, ${companyPosition.company.address}</li>
            </ul>
        </div>
    </a>
    <!-- Job List Start -->
</c:forEach>

<!-- Job List Start -->
<!-- 分页 -->
<!-- Pagination Start -->
<ul class="pagination pagination-center mt-5">

    <li class="page-item"><a class="page-link" id="prePage" data-id="${pageInfo.pageNum-1}"><i class="fa fa-angle-left"></i></a></li>

    <c:if test="${pageInfo.pages>=5}">
        <c:if test="${pageInfo.pageNum>=3 && pageInfo.pageNum<=pageInfo.pages-2}">
            <c:forEach begin="${pageInfo.pageNum-2}" end="${pageInfo.pageNum+2}" var="stat">
                <c:if test="${stat eq pageInfo.pageNum}">
                    <li class="page-item active"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
                </c:if>
                <c:if test="${stat ne pageInfo.pageNum}">
                    <li class="page-item"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
                </c:if>
            </c:forEach>
        </c:if>
        <c:if test="${pageInfo.pageNum<3}">
            <c:forEach begin="1" end="5" var="stat">
                <c:if test="${stat eq pageInfo.pageNum}">
                    <li class="page-item active"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
                </c:if>
                <c:if test="${stat ne pageInfo.pageNum}">
                    <li class="page-item"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
                </c:if>
            </c:forEach>
        </c:if>
        <c:if test="${pageInfo.pageNum>pageInfo.pages-2}">
            <c:forEach begin="${pageInfo.pages-4}" end="${pageInfo.pages}" var="stat">
                <c:if test="${stat eq pageInfo.pageNum}">
                    <li class="page-item active"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
                </c:if>
                <c:if test="${stat ne pageInfo.pageNum}">
                    <li class="page-item"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
                </c:if>
            </c:forEach>
        </c:if>
    </c:if>
    <c:if test="${pageInfo.pages<5}">
        <c:forEach begin="1" end="${pageInfo.pages}" var="stat">
            <c:if test="${stat eq pageInfo.pageNum}">
                <li class="page-item active"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
            </c:if>
            <c:if test="${stat ne pageInfo.pageNum}">
                <li class="page-item"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
            </c:if>
        </c:forEach>
    </c:if>

    <li class="page-item"><a class="page-link" id="nextPage" data-id="${pageInfo.pageNum+1}"><i class="fa fa-angle-right"></i></a></li>

</ul>
<!-- Pagination End -->

<script type="text/javascript" src="<%=path%>/assets/js/vendor/jquery-3.4.1.min.js"></script>
<script type="text/javascript">
    $(function () {
        function getValue(pageNum){
            $.ajax({
                url:"<%=path%>/web/company/position",
                type:"post",
                data:{pageNum:pageNum,companyId:${company.id}},
                success:function (data) {
                    $(".job-list-wrap").html(data);
                }
            });
        }
        $.each($("a[id^=page]"),function () {
            $(this).on("click",$(".job-list-wrap"),function () {
                var pageNum = $(this).attr("data-id");
                getValue(pageNum);
            })
        });
        $("#prePage").on("click",$(".job-list-wrap"),function () {
            var pageNum = $("#prePage").attr("data-id");
            if(pageNum<=0){
                pageNum = 1;
            }
            getValue(pageNum);
        });
        $("#nextPage").on("click",$(".job-list-wrap"),function () {
            var pageNum = $("#nextPage").attr("data-id");
            if(pageNum>${pageInfo.pages}){
                pageNum = ${pageInfo.pages};
            }
            getValue(pageNum);
        });
    });
</script>
